<?php
// 监听本地的9000端口
$socket = stream_socket_server("tcp://localhost:9000", $errno, $errstr);
 
if (!$socket) {
    die("创建套接字失败: ($errno) $errstr\n");
}
 
echo "监听端口9000成功\n";
 
// 接受一个连接
$connection = stream_socket_accept($socket, -1);
 
if ($connection) {
    // 从客户端接收数据
    $data = fread($connection, 1024);
 
    // 回显数据
    fwrite($connection, $data);
 
    fclose($connection);
}
 
fclose($socket);
